﻿using System.Collections.Generic;
using System.Data;

namespace LuDragon.IService
{
    public interface IDapperBaseService
    {

        #region WriteDB

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model">表实体</param>
        /// <param name="dbWrite">写数据库连接</param>
        /// <param name="transaction">事物</param>
        /// <returns></returns>
        void Add<TModel>(TModel model, IDbConnection dbWrite = null, IDbTransaction transaction = null) where TModel : class;

        /// <summary>
        /// 批量添加数据信息
        /// </summary>
        /// <param name="list">实体集合</param>
        /// <param name="dbWrite">写数据库连接</param>
        /// <param name="transaction">事物</param>
        /// <returns></returns>
        void Add<TModel>(IEnumerable<TModel> list, IDbConnection dbWrite = null, IDbTransaction transaction = null) where TModel : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model">表实体</param>
        /// <param name="dbWrite">写数据库连接</param>
        /// <param name="transaction">事物</param>
        /// <returns></returns>
        void Update<TModel>(TModel model, IDbConnection dbWrite = null, IDbTransaction transaction = null) where TModel : class;

        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="list">实体集合</param>
        /// <param name="dbWrite">写数据库连接</param>
        /// <param name="transaction">事物</param>
        /// <returns></returns>
        void Update<TModel>(IEnumerable<TModel> list, IDbConnection dbWrite = null, IDbTransaction transaction = null) where TModel : class;

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model">表实体</param>
        /// <param name="dbWrite">写数据库连接</param>
        /// <param name="transaction">事物</param>
        /// <returns></returns>
        void Delete<TModel>(TModel model, IDbConnection dbWrite = null, IDbTransaction transaction = null) where TModel : class;

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="list">实体集合</param>
        /// <param name="dbWrite">写数据库连接</param>
        /// <param name="transaction">事物</param>
        /// <returns></returns>
        void Delete<TModel>(IEnumerable<TModel> list, IDbConnection dbWrite = null, IDbTransaction transaction = null) where TModel : class;

        /// <summary>
        /// 执行sql语句
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="dbWrite">写数据库连接</param>
        /// <param name="transaction">事物</param>
        /// <returns></returns>
        int Execute(string sql, IDbConnection dbWrite = null, IDbTransaction transaction = null);

        #endregion

        #region ReadDB

        /// <summary>
        /// 获取实体数据信息
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        TModel GetModel<TModel>(object id) where TModel : class;

        /// <summary>
        /// 获取实体所有数据信息列表
        /// </summary>
        /// <returns></returns>
        IEnumerable<TModel> GetAll<TModel>() where TModel : class;

        /// <summary>
        /// 查询数据列表
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns></returns>
        IEnumerable<T> Query<T>(string sql, object param = null) where T : class;
      
        #endregion
    }
}
